﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.IService.Formula;
using Zhp.Model.Common;
using Zhp.Model.Formula;

namespace Zhp.Api.Controllers.Formula
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Formula)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Formula, Name = "公式变量", Order = 1, RouterName = "formulavariable", WebFilePath = "formula/formulaVariable/index", Icon = "variable")]
    public class FormulaVariableController : ControllerBase
    {
        private readonly IFormulaVariableService _formulaVariableService;
        public FormulaVariableController(IFormulaVariableService formulaVariableService)
        {
            _formulaVariableService = formulaVariableService;
        }

        [HttpPost]
        [SeedList("变量列表", "公式变量", ApiGroupEnum.Formula)]
        public async Task<PageRet<FormulaVariableModel>> Query(FormulaVariableSearch search)
        {
            var list = await _formulaVariableService.Query(search);

            return new PageRet<FormulaVariableModel>
            {
                DataList = list,
                TotalCount = search.TotalCount,
            };
        }

        [HttpPost]
        [SeedButton("新增", "变量列表", "公式变量", ApiGroupEnum.Formula, ["/api/FormulaVariable/QueryVariableClass", "/api/FormulaVariable/QueryVariable"])]
        public async Task<bool> Create(FormulaVariableEdit p)
        {
            return await _formulaVariableService.Create(p);
        }

        [HttpPut()]
        [SeedButton("修改", "变量列表", "公式变量", ApiGroupEnum.Formula, ["/api/FormulaVariable/QueryVariableClass", "/api/FormulaVariable/QueryVariable"])]
        public async Task<bool> Update(FormulaVariableEdit p)
        {
            return await _formulaVariableService.Update(p);
        }

        [HttpDelete("{id}")]
        [SeedButton("删除", "变量列表", "公式变量", ApiGroupEnum.Formula)]
        public async Task<bool> Delete(long id)
        {
            return await _formulaVariableService.Delete(id);
        }

        [HttpGet]
        public async Task<List<FormulaVariableList>> QueryFormulaVariable()
        {
            return await _formulaVariableService.QueryFormulaVariable();
        }

        [HttpGet]
        public async Task<List<FormulaVariableSelect>> QueryVariableClass()
        {
            return await _formulaVariableService.QueryVariableClass();
        }

        [HttpGet]
        public async Task<List<FormulaVariableSelect>> QueryVariable(string variableClass)
        {
            return await _formulaVariableService.QueryVariable(variableClass);
        }
    }
}
